import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('../views/HomeView.vue')
    },
    {
      path: '/demo',
      name: 'demo',
      component: () => import('../views/DemoView.vue')
    },
    {
      path: '/algorithms',
      name: 'algorithms',
      component: () => import('../views/AlgorithmsView.vue')
    },
    {
      path: '/api-docs',
      name: 'api-docs',
      component: () => import('../views/ApiDocsView.vue')
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    },
    {
      path: '/bonus-compare',
      name: 'bonus-compare',
      component: () => import('../views/BonusCompareView.vue')
    },
    {
      // 捕获所有未匹配的路由，重定向到首页
      path: '/:pathMatch(.*)*',
      redirect: '/'
    }
  ],
  // 平滑滚动到页面顶部
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0, behavior: 'smooth' }
    }
  }
})

export default router